package projectManagement;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LogInGUI extends JPanel implements ActionListener{
	private JTextField textName;
	private JPasswordField passwordField;
	
	ClientGUI cGUI;
	private static ClientLogic clientLogic;
	
	public LogInGUI(ClientGUI cGui) {
		setPreferredSize(new Dimension(399, 213));
		setLayout(null);
		
		this.cGUI = cGUI;
		
		JButton btnLogIn = new JButton("Log In");
		btnLogIn.setBounds(155, 158, 89, 35);
		btnLogIn.putClientProperty("Quaqua.Button.style", "bevel");
		btnLogIn.addActionListener(this);
		add(btnLogIn);
		
		textName = new JTextField();
		textName.setBounds(84, 47, 231, 35);
		add(textName);
		textName.setColumns(10);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(84, 110, 231, 35);
		add(passwordField);
		
		JLabel lblUsserName = new JLabel("UsserName:");
		lblUsserName.setBounds(83, 33, 83, 14);
		add(lblUsserName);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setBounds(84, 97, 82, 14);
		add(lblPassword);
		
		JFrame f = new JFrame();
		f.getContentPane().add(this);
		f.setResizable(false);
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		f.pack();
		f.setLocationRelativeTo(null);
	}

	@Override
	public void actionPerformed(ActionEvent btn) {
		String cmd = btn.getActionCommand();
		
		if(cmd.equalsIgnoreCase("Log In")){
			System.out.println(textName.getText()+ String.valueOf(passwordField.getPassword()));
			cGUI.setCredential(textName.getText(), String.valueOf(passwordField.getPassword()));
			
			clientLogic = new ClientLogic(cGUI);
			clientLogic.start();
		}
		
	}
}
